//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_TERRAIN_H
#define _UX_TERRAIN_H

#include "CMegaTexture.h"
//#include "CTerrainLoader.h"
#include "../Materials/CMaterial.h"

namespace Engine
{
namespace Resources
{


	//
	// Terrain Updater interface
	//

	class ITerrainUpdater : public IRefCountable, public IMegaTextureUpdater
	{
	public:
		virtual void Update(CTerrain *) = 0;

		// IMegaTextureUpdater //
		//virtual bool operator () (CMegaTexture *) = 0;
	};



	//
	// Terrain Init
	//

	/*struct TTerrainInit
	{
		ITerrainUpdater		*	pUpdater;
		TMegaTexDescr			sMegaTex;
		TMaterialInit			sMaterial;
		//CBaseProgramShellPtr	pTessLevel;	// build tessellation level map
		///
		TTerrainInit() {}
	};*/



	//
	// Terrain
	//

	/*class _EXPORT_ CTerrain : public CResource
	{
	public:
		template <typename T>
		struct TROParams
		{
			const TQuaternion<T> &	sCameraOrient;
			const TMatrix<T,4,4> &		sModelMatrix;
			T						tVisDistance;
			///
			TROParams(const TQuaternion<T> &q, const TMatrix<T,4,4> &m, T vd):
				sCameraOrient(q), sModelMatrix(m), tVisDistance(vd)
			{}
		};

	protected:
		struct TTerrainLayer
		{
			IProgramMaterial *	pMaterial;
			uint8				uLOD;
			///
			TTerrainLayer(): pMaterial(nullptr), uLOD(0) {}
		};
		typedef array< TTerrainLayer >		layers_array_t;

	protected:
		layers_array_t			_aLayers;
		CMeshPtr				_pGrid;
		ITerrainUpdaterPtr		_pUpdater;
		//CBaseProgramShellPtr	_pTessLevelProg;
		//CTexturePtr				_pTessLevelMap;
		CMegaTexture			_cMegaTexture;
		CMaterial				_cMaterial;
		aabb_f					_sBBox;
		float					_fMaxHeight;

	protected:
		CTerrain(const char *pFileName);
		virtual ~CTerrain();

		virtual bool _Replace(CResource *pRes);
		virtual bool _Load(IFilePtr pFile, uint uSize);
		virtual bool _Save(IFilePtr pFile);
		virtual bool _Reload(IFilePtr pFile, bool bRecursive);

		static  void _s_Draw(void *, void *);

	public:
		bool Create(const TTerrainInit &);


		bool Render(const TROParams<float> &sParams, TCameraRenderQueue *pCRQ);

		//void  Draw();
		void  SetupCamera(const mat4 &sViewMatrix);

		virtual void Destroy();
		virtual bool Compare(CResource *pRes);
		
		virtual bool				IsValid() const	{ return false; }
		virtual e_resource::type	GetType() const	{ return e_resource::TERRAIN; }

		static CTerrainPtr s_CreateTerrain(const char *pFileName);
	};*/

//-------------------------------------------------------------------

}	// EngineResource
}	// Engine

#endif	// _UX_TERRAIN_H